<?php

namespace app\index\controller;

use tian\Session;

class Hone extends Base
{
    public function index()
    {
        try {
            $role_id = Session::get('uid');

            $infoRole = model('Role')->getInfo($role_id);
            $this->assign('infoRole', $infoRole);

            $roleStatus = state_hone($infoRole['ulv']);
            $this->assign('roleStatus', $roleStatus);

            $this->fetch('index');
        } catch (\Throwable $e) {
            echo $e->getMessage();
        }
    }

    public function upgrade()
    {
        try {
            $role_id = Session::get('uid');
            $modelRole = model('Role');

            $infoRole = $modelRole->getInfo($role_id);
            $roleStatus = state_hone($infoRole['ulv']);

            if($infoRole['uexp'] < $roleStatus['exp']){
                returnJson(0, '修为不足');
            }

            if($roleStatus['honeStatus']==1){
                $increase = 10;
            }else{
                $increase = 1;
            }

            $temp = [
                'uid' => $role_id,
                'ulv' => $infoRole['ulv'] + 1,
                'uexp' => round($infoRole['uexp'] - $roleStatus['exp']),
                'utz' => $infoRole['utz'] + $increase,
                'ugg' => $infoRole['ugg'] + $increase,
                'ull' => $infoRole['ull'] + $increase,
                'umj' => $infoRole['umj'] + $increase,
            ];
            $modelRole->saved($temp);

            //四维属性折算
            $modelRole->setAttributeConvert($role_id);

            returnJson(1, 'ok');
        } catch (\Throwable $e) {
            echo $e->getMessage();
        }
    }
}
